/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facades;

import entities.Candidate;
import entities.CandidateTags;
import entities.Search;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Alvaro
 */
@Stateless
public class CandidateTagsFacade extends AbstractFacade<CandidateTags> {
    @PersistenceContext(unitName = "ProyectoPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CandidateTagsFacade() {
        super(CandidateTags.class);
    }
    
    
    public List<String>similarTags(String parameter){
        List<String>res= new ArrayList<String>();
        Query namedQuery=em.createNamedQuery("CandidateTags.findByTag");
        namedQuery.setParameter("tag", "%"+parameter+"%");
        List<String>objects =namedQuery.getResultList();
        if(!objects.isEmpty()){
            for(String string:objects){
                res.add(string);
            }
        }
        return res;
    }
    
    public Boolean candidateHasThisTag(Candidate candidate,String tag){
        Query namedQuery=em.createNamedQuery("CandidateTags.findByCandidateAndTag");
        namedQuery.setParameter("candidate", candidate);
        namedQuery.setParameter("tag", tag);
        return !namedQuery.getResultList().isEmpty();
    }
}
